package web.servlet;

import domain.LineItem;
import domain.Order;
import service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class ViewOrderServlet extends HttpServlet {

    private static final String VIEW_ORDER = "/WEB-INF/jsp/order/viewOrder.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrderService orderService=new OrderService();
        HttpSession session= req.getSession();
        String orderid=req.getParameter("orderId");
        System.out.println("viewOrderServlet   orderid="+orderid);
        Order order= orderService.getOrderByOrderId(Integer.parseInt(orderid));
        List<LineItem> itemList=orderService.getLineItemByOrderId(Integer.parseInt(orderid));
        order.setLineItems(itemList);
        session.setAttribute("order",order);
        req.getRequestDispatcher(VIEW_ORDER).forward(req,resp);
    }
}
